package com.shop.auth.service.impl;

import com.shop.auth.domain.SysUser;
import com.shop.auth.service.UserService;
import com.shop.domain.User;
import com.shop.feign.UserFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserFeign userFeign;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        try {
            User userselect = new User();
            userselect.setUsername(username);
            User user = userFeign.select(userselect).getData().get(0);
            SysUser sysUser = new SysUser();
            sysUser.setId(Long.valueOf(user.getId()));
            sysUser.setUsername(user.getUsername());
            sysUser.setPassword(user.getPassword());
            sysUser.setRoles(user.getRole());
            return sysUser;
        } catch (Exception e) {
            return null;
        }
    }

}
